class Admin::ReportsController < AdminController

  def hour_bank
    @result = ActiveRecord::Base.connection.execute("SELECT * FROM extra_hours")
  end
  
  def hours
    @users = User.all
    @month = params[:month].to_i unless params[:month].blank?
    @month_obj = Time.parse([Time.now.year, @month, '01'].join('-')) unless @month.blank?
    @months = []
    Date::MONTHNAMES.each_with_index do |month, index|
      @months << [t("month_" + month.downcase), index.to_i] unless month.nil?
    end
  end
  
  def holidays
    @result = ActiveRecord::Base.connection.execute("SELECT * FROM year_holidays WHERE branch_office_id = #{BranchOffice.default.id}")
  end
  
  def users
    @result = ActiveRecord::Base.connection.execute("SELECT * FROM user_info")
  end

  def update_reports
    config = ActiveRecord::Base.connection.instance_variable_get("@config")
    if config[:adapter] == "mysql"
      mysql_file = "#{RAILS_ROOT}/script/mysql/views.sql"
      %x[mysql -u#{config[:username]} -p"#{config[:password]}" -h #{config[:host]} #{config[:database]} < '#{mysql_file}']
    end
    flash[:notice] = t(:reports_updated)
    redirect_to :back
  end
  
  private

  def collection
    []
  end

  def object
    nil
  end

  def model_name
    'hour'
  end

end
